<template>
    <div>
        <div style="margin-bottom: 20px">
            <el-divider></el-divider>
            <div style="float: left;top:0px">
                <i style="float: left;margin-top:-3px" class="el-icon-document-checked"></i><span
                    style="float:left;font-size: large">窗口挂号</span>
                <br><br><br><br>
                <el-button style="margin-left: 5px" type="primary" @click="Register">挂号</el-button>
                <el-button style="margin-left: 5px" type="warning" @click="resetForm">清空</el-button>

            </div>
            <br>
            <el-divider></el-divider>
            <br>
        </div>
        <el-divider></el-divider>
        <br>
        <div>
            <span style="font-size: large;float:left">基本信息</span>
            <br><br><br><br>
        </div>
        <div>
            <el-form :inline="true" label-width="100px" ref="RegisterForm" :model="RegisterForm">
                <el-form-item style="float:left" label="病历号">
                    <el-input v-model="RegisterForm.caseNumber" placeholder="病历号" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item style="float:left;margin-left:30px" label="姓名">
                    <el-input v-model="RegisterForm.realName" placeholder="请输入姓名"></el-input>
                </el-form-item>
                <el-form-item style="margin-left:50px;float:left" label="身份证号">
                    <el-input v-model="RegisterForm.cardNumber" placeholder="请输入身份证号"></el-input>
                </el-form-item>
                <el-form-item style="float:left;margin-left:14px;" label="年龄">
                    <el-input v-model="RegisterForm.age" placeholder="请输入年龄"></el-input>
                </el-form-item>

                <el-form-item style="float:left" label="性别">
                    <el-select v-model="RegisterForm.gender" placeholder="请选择">
                        <el-option v-for="item in genders" :key="item" :label="item" :value="item">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item style="margin-left:13px;float: left" label="家庭住址">
                    <el-input v-model="RegisterForm.homeAddress" style="width: 400px" type="textarea"
                        placeholder="请输入家庭住址"></el-input>
                </el-form-item>
            </el-form>
        </div><br><br><br><br><br><br><br><br><br><br>
        <el-divider></el-divider>
        <br>
        <div>
            <span style="font-size: large;float:left">挂号信息</span>
            <br><br><br><br>
        </div>
        <el-form :inline="true" label-width="100px" ref="RegisterForm" :model="RegisterForm">
            <el-form-item style="float:left;margin-left:-1px" label="结算类别">
                <el-select v-model="RegisterForm.settleCategoryName" placeholder="请选择">
                    <el-option v-for="item in settleCategoryNames" :key="item" :label="item" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item style="float:left;margin-left:15px" label="挂号科室">
                <el-select v-model="RegisterForm.deptName" placeholder="请选择">
                    <el-option v-for="item in deptNames" :key="item" :label="item" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item style="float:left;margin-left:30px" label="看诊日期">
                <el-input v-model="RegisterForm.visitDate" placeholder="看诊日期" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item style="float:left;margin-left:20px" label="挂号级别">
                <el-select v-model="RegisterForm.registName" placeholder="请选择">
                    <el-option v-for="item in registNames" :key="item" :label="item" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item style="float:left;margin-left:-1px" label="午别">
                <el-input v-model="RegisterForm.noon" placeholder="午别" :disabled="true"></el-input>
            </el-form-item>
            <br>
            <el-form-item style="float:left;margin-left:30px" label="收费方式">
                <el-select v-model="RegisterForm.registMethod" placeholder="请选择">
                    <el-option v-for="item in registMethods" :key="item" :label="item" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item style="float:left;margin-left:30px;" label="看诊医生">
                <el-select v-model="RegisterForm.employeeName" placeholder="请选择">
                    <el-option v-for="item in employeeNames" :key="item" :label="item" :value="item">
                    </el-option>
                </el-select>
                <el-button style="float:right;margin-top:0px;width:100px;margin-left:20px;" icon="el-icon-search"
                    type="primary" @click="selectDoctor">搜索</el-button>
            </el-form-item>
            <div>
                <el-switch style="float:left;margin-top:10px;margin-left:58px" v-model="RegisterForm.isBook"
                    active-color="#13ce66" inactive-color="#ff4949" active-text="病历本" active-value="是" inactive-value="否">
                </el-switch>

            </div>
            <el-form-item style="float:left;margin-left:70px" label="挂号金额">
                <el-input v-model="registFee" placeholder="挂号金额" :disabled="true"></el-input>
            </el-form-item>
        </el-form>


    </div>
</template>

<script>
import axios from 'axios';
export default {
    data() {
        return {
            RegisterForm: {
                caseNumber: '',
                realName: '',
                gender: '',// 存储用户选择的性别
                cardNumber: '',
                age: '',
                homeAddress: '',
                visitDate: null,
                noon: '',
                deptName: '',
                employeeName: '',
                registName: '',
                settleCategoryName: '',
                isBook: '',//是否要病历
                registMethod: '',
                //挂号金额
                //visitState:''
            },
            genders: ["男", "女"],// 存储性别值的数组
            deptNames: [],//储存挂号科室的数组
            employeeNames: [],//储存医生的数组
            registNames: [],//储存挂号级别的数组
            registMethods: ['现金', '银行卡', '医保卡', '微信', '支付宝'],
            settleCategoryNames: [],
            //查寻医生要的参数，也是返回的参数
            registLevelId: '',
            deptId: '',
            registFee: ''//挂号费用
        };
    },
    methods: {
        //插入挂号数据：
        async Register(){
            await axios.get("http://127.0.0.1:8088/register/insert",
             { params: {
                realName:this.RegisterForm.realName,
                gender:this.RegisterForm.gender,
                cardNumber:this.RegisterForm.cardNumber,
                age:this.RegisterForm.age,
                homeAddress:this.RegisterForm.homeAddress,
                visitDate:this.RegisterForm.visitDate,
                noon: this.RegisterForm.noon,
                deptName: this.RegisterForm.deptName,
                employeeName: this.RegisterForm.employeeName,
                registName: this.RegisterForm.registName,
                settleCategoryName: this.RegisterForm.settleCategoryName,
                isBook: this.RegisterForm.isBook,//是否要病历
                registMethod: this.RegisterForm.registMethod
             } }).then((res) => {
                console.log(res.data.data)
                this.$message.success("挂号成功")
            });
            console.log(this.RegisterForm)
        },
        //点击搜索时：搜索医生
        async selectDoctor() {
            //根据name换id
            //参数：String deptName
            await axios.get("http://127.0.0.1:8088/department/getIdByName", { params: { deptName: this.RegisterForm.deptName } }).then((res) => {
                this.deptId = res.data.data
                console.log(this.deptId)
            });
            //参数：String registName
            await axios.get("http://127.0.0.1:8088/registLevel/getIdFeebyName", { params: { registName: this.RegisterForm.registName } }).then((res) => {
                // this.registLevelId = res.data.data
                this.registLevelId = res.data.data.id
                this.registFee = res.data.data.registFee
                if (this.RegisterForm.isBook == "是") {
                    this.registFee = this.registFee + 2;
                }
                console.log(this.registLevelId)
                console.log(this.registFee)
            });

            // 初始化时间和午别和医生
            // 参数：int registLevelId,int deptId
            await axios.get("http://127.0.0.1:8088/register/getDoctor", { params: { registLevelId: this.registLevelId, deptId: this.deptId } }).then((res) => {
                // this.registNames=res.data.data
                this.employeeNames = res.data.data.doctorName
                this.RegisterForm.noon = res.data.data.noon
                this.RegisterForm.visitDate = res.data.data.visitDate
                console.log(res.data.data)
            });
        },
        //重置
        resetForm() {
            this.RegisterForm=[]
        },
    },
    async mounted() {
        //获取病历号
        await axios.get("http://127.0.0.1:8088/register/getCaseNum").then((res) => {
            this.RegisterForm.caseNumber = res.data.data
            console.log(this.RegisterForm.caseNumber)
        });
        //初始化下拉列表
        await axios.get("http://127.0.0.1:8088/settleCategory/getAllSettleCategory").then((res) => {
            this.settleCategoryNames = res.data.data
            console.log(this.settleCategoryNames)
        });
        await axios.get("http://127.0.0.1:8088/department/getAllDept").then((res) => {
            this.deptNames = res.data.data
            console.log(this.deptNames)
        });
        await axios.get("http://127.0.0.1:8088/registLevel/getAllRegistLevel").then((res) => {
            this.registNames = res.data.data
            console.log(this.registNames)
        });
    }
};

</script>